package com.ost.kautilya.modeling.weka;

import com.ost.kautilya.modeling.EvaluationMetric;
import com.ost.kautilya.modeling.ModelEvaluation;
import com.ost.kautilya.utils.Metric;
import com.ost.kautilya.utils.StatisticalMetric;
import com.ost.kautilya.utils.Metric.DataType;

import weka.classifiers.timeseries.eval.TSEvalModule;
import weka.classifiers.timeseries.eval.TSEvaluation;

public class WekaTSFEvaluation extends ModelEvaluation {
	private static final long serialVersionUID = 1L;

	public WekaTSFEvaluation(TSEvaluation ev, int predictionSize, int classCount, byte[] output) throws Exception {
		super(classCount, output);
		StatisticalMetric[] metrics = new StatisticalMetric[classCount];
		for (int i = 0; i < classCount; i++) {
			metrics[i] = Metric.newMetric(Metric.MEAN, DataType.DOUBLE);
		}
		while (--predictionSize > 0) {
			TSEvalModule error = ev.getEvaluateOnTestData() ? ev.getPredictionsForTestData(1) : (ev.getEvaluateOnTrainingData() ? ev.getPredictionsForTrainingData(1) : null);
			if (error != null) {
				double[] vals = error.calculateMeasure();
				for (int i = 0; i < classCount; i++) {
					double val = vals[i];
					metrics[i].push(0, val);
				}
			}
		}
		for (int i = 0; i < classCount; i++) {
			setMetric(i, EvaluationMetric.SUM_OF_ERRORS, metrics[i].value().doubleValue());
		}
	}

}
